#!/usr/bin/python
# -*- coding: utf-8 -*-
# Description: fill datas
# Create: 2008-7-14
# Author: MK2[fengmk2@gmail.com]

import MySQLdb

def get_cursor():
    ''''''
    cursor = None
    while cursor is None:
        try:
            connection = MySQLdb.connect('192.168.48.249', 'root', 'sonic', 'peurl', charset='utf8')
            cursor = connection.cursor()
        except Exception, e:
            print e, 'sleep 10 secs,'
            cursor = None
            time.sleep(10)
    return cursor

def main():
    cursor = get_cursor()
    sql = 'select url from link'
    cursor.execute(sql)
    rs = cursor.fetchall()
    insert = 'insert into task (url) values(%s)'
    print len(rs)
    for r in rs:
        print r
        cursor.execute(insert, r[0])
    
if __name__ == '__main__':
    main()

    